//
//  IOTVC.m
//  QoilPublic
//
//  Created by SunChao on 2018/4/13.
//  Copyright © 2018年 孙超. All rights reserved.
//

#import "IOTVC.h"
#import "IOTMapVC.h"
#import "IOTEquipmentVC.h"
#import "BoxVC.h"
@interface IOTVC ()<UIScrollViewDelegate>
{
    UIScrollView *_myScrollView;
}

@property (nonatomic,strong)IOTMapVC *mapVC;
@property (nonatomic,strong)IOTEquipmentVC *equipmentVC;

@end

@implementation IOTVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray *segmentedArray = [NSArray arrayWithObjects:@"地图",@"列表",nil];
    
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];
    
    segmentedControl.frame = CGRectMake(0, 0, 140, 30);
    
    segmentedControl.selectedSegmentIndex = 0;
    
    segmentedControl.tintColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.9];
    
    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    
    [segmentedControl addTarget:self action:@selector(handelSegementControlAction:)
     
               forControlEvents:UIControlEventValueChanged];
    
    [self.navigationItem setTitleView:segmentedControl];
    
    //定制右按钮
    
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    
    but.frame =CGRectMake(0,0, 60, 44);
    
    [but setTitle:@"小马云盒"forState:UIControlStateNormal];
    [but setFont:[UIFont systemFontOfSize:13]];
    [but addTarget:self action:@selector(PushToIOTVC)forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem  *barBut = [[UIBarButtonItem alloc]initWithCustomView:but];
    
    self.navigationItem.rightBarButtonItem = barBut;
    [self addScrollView];

}


- (void)PushToIOTVC{
    BoxVC *vc = [[BoxVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

//[dubai]点击分段控制执行相应的方法
-(void)addScrollView{
    _myScrollView = [[UIScrollView alloc]initWithFrame:
                    CGRectMake(0, 0, kScreenWidth, screenHeight)];
   
    _myScrollView.contentSize = CGSizeMake(2*kScreenWidth,
                                         screenHeight);
    _myScrollView.delegate = self;
    _myScrollView.scrollEnabled = NO;
    [self.view addSubview:_myScrollView];
    _myScrollView.contentOffset = CGPointMake(0, 0);
    self.mapVC = [[IOTMapVC alloc]init];
    [self addChildViewController:self.mapVC];
    [self.view addSubview:self.mapVC.view];
    self.mapVC.view.frame = CGRectMake(0, 64, kScreenWidth, kScreenHeight-64);
    self.equipmentVC = [[IOTEquipmentVC alloc]init];
    [self addChildViewController:self.equipmentVC];
    [self.view addSubview:self.equipmentVC.view];
    self.equipmentVC.tbView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    self.equipmentVC.view.hidden = YES;
    
}
- (void)handelSegementControlAction:(UISegmentedControl *)segment

{
    
    NSLog(@"%s",__FUNCTION__);
    
    switch (segment.selectedSegmentIndex) {
            
        case 0:
            
        {
//            _myScrollView.contentOffset = CGPointMake(0, 0);
            self.mapVC.view.hidden =NO;
            self.equipmentVC.view.hidden = YES;
            break;
        }
        case 1:
            
        {
//            _myScrollView.contentOffset = CGPointMake(kScreenWidth, 0);
            self.mapVC.view.hidden = YES;
            self.equipmentVC.view.hidden = NO;
            
            break;
        }
        
            
        default:
            break;
    }
}

@end
